package com.homedo.odin.solution.enumcode.pay;

import java.util.HashMap;
import java.util.Map;

public enum ReturnCode {
    SUCCEED(0), FAILURE(1), SYS_ERR(99999), DEPRECATED(9999),

    //common
    INVALID_PARAMS(1000), MISSING_PARAMS(1001), UNAUTH_REQUEST(1002), TARGET_NOT_FOUND(1004), TARGET_EXISTS(
            1005), OPERATOR_FORBBID(1006),
    NOT_SUPPORTTED(1007),

    AUTHROIZATION_FAILED(2002),
    HTTP_CONNECTION_ERROR(5000);


    private int value;

    private ReturnCode(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public static String returnCodeMsg(ReturnCode rt) {
        return map.get(rt);
    }

    public static ReturnCode getWebReturnCode(int value) {
        for (ReturnCode code : ReturnCode.values()) {
            if (value == code.getValue()) {
                return code;
            }
        }

        return null;
    }

    private static Map<ReturnCode, String> map = new HashMap<ReturnCode, String>();

    static {
        map.put(SUCCEED, "成功");
        map.put(FAILURE, "失败");
        map.put(INVALID_PARAMS, "输入参数有错");
        map.put(MISSING_PARAMS, "缺少参数");
        map.put(SYS_ERR, "系统错误");
        map.put(DEPRECATED, "接口已废弃");
        map.put(OPERATOR_FORBBID, "无权操作");
        map.put(TARGET_NOT_FOUND, "目标不存在");
        map.put(TARGET_EXISTS, "目标已存在");
        map.put(HTTP_CONNECTION_ERROR, "HTTP内部调用请求异常");
        map.put(NOT_SUPPORTTED, "不支持的操作");

    }

}
